package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.*;

public class CheckingAccount extends AbstractAccount {

	private double overdraft;
	
	public CheckingAccount(double amount, double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}

	@Override
	public int withdraw(double amount) throws OverDraftLimitExceededException, IllegalAmountArgumentException {
		if (amount <= 0 ) {
			throw new IllegalAmountArgumentException(amount);
		}
		if (maximumAmountToWithdraw() < amount) {
			throw new OverDraftLimitExceededException(
					this.maximumAmountToWithdraw()-amount);
		}
		
		balance -= amount;
		return 0;
	}
	
	@Override
	public double maximumAmountToWithdraw() {
		return balance+overdraft;
	}

}
